package com.bysj.lms.config;

import com.bysj.lms.properties.UploadProperties;
import com.bysj.lms.utils.LocalDateConverter;
import com.bysj.lms.utils.StringTOLacalDateConverter;
import com.bysj.lms.utils.UploadUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

@Configuration
public class MyMvc extends WebMvcConfigurationSupport {

    @Autowired
    UploadProperties uploadProperties;

    @Override
    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/swagger-ui/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/springfox-swagger-ui/")
                .resourceChain(false);
        registry.addResourceHandler("/image/**")
                .addResourceLocations("file:"+ UploadUtil.getPath());
        System.out.println(UploadUtil.getPath());
        super.addResourceHandlers(registry);
    }

    protected void addFormatters(FormatterRegistry registry) {
        registry.addConverter(new StringTOLacalDateConverter());
    }
}
